<template>
	<div>
		<template v-if="vtInfo === 'tb'">
			<tbTree :treeType="treeType" />
		</template>
		<template v-else>
			<LinxYunTree :treeType="treeType" :title="title" :treeAttr="treeAttr" />
		</template>
	</div>
</template>

<script lang="js">
import LinxYunTree from '/@/components/Linxyun/TreeData/LinxYunTree.vue';
import tbTree from '/@/components/Linxyun/TbTreeData/parentNode.vue';

export default {
	components: {
		LinxYunTree,
		tbTree,
	},
	data() {
		return {
			treeType: null,
			title: 'xxxx',
			vtInfo: '',
			treeAttr: { treeKey: -1, isEdit: false, isCheckBox: true },
		};
	},
	created() {
		console.log('[Debug][DataDictTree]Uri path: ', this.$router.currentRoute.value.fullPath);
		console.log('query: ', this.$router.currentRoute.value.query)
		console.log('params: ', this.$router.currentRoute.value.params)
		this.parseRoutePath();
		if (this.treeType === null || this.treeType === '') {
			this.$message({
				message: '页面错误，ErrorCode: 880320',
				type: 'error',
				duration: BASE_API.MSG_SHOW_TIME,
			});
			// 退回到上一个页面。
			this.$router.go(-1);
		}
		console.log('[Debug]ty: ', this.treeType, ', ea: ', this.treeAttr.isEdit);
	},
	methods: {
		parseRoutePath() {
			const pathParamIdx = this.$router.currentRoute.value.fullPath.lastIndexOf('/');
			if (pathParamIdx < 0) {
				this.$message({
					message: '页面错误，ErrorCode: 880320',
					type: 'error',
					duration: BASE_API.MSG_SHOW_TIME,
				});
				// 退回到上一个页面。
				this.$router.go(-1);
			}

			const paramString = this.$router.currentRoute.value.fullPath.slice(pathParamIdx + 1);
			if (paramString === undefined || paramString === '') {
				this.$message({
					message: '页面错误，ErrorCode: 880320',
					type: 'error',
					duration: BASE_API.MSG_SHOW_TIME,
				});
				// 退回到上一个页面。
				this.$router.go(-1);
			}
			const params = paramString.split('&');

			let keyValue = null;
			for (let i = 0; i < params.length; i++) {
				keyValue = params[i].split('=');
				if (!keyValue || keyValue.length !== 2) {
					this.$message({
						message: '页面错误，ErrorCode: 880320',
						type: 'error',
						duration: BASE_API.MSG_SHOW_TIME,
					});
					// 退回到上一个页面。
					this.$router.go(-1);
				}
				if (keyValue[0] === 'ty') {
					this.treeType = keyValue[1];
				} else if (keyValue[0] === 'ea') {
					this.treeAttr.isEdit = keyValue[1] !== '0';
				}
				if (keyValue[0] === 'vt') {
					this.vtInfo = keyValue[1];
				}
			}
		},
	},
};
</script>
